﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.ApiResults;
using T.Personnel.API.Application.Command.EntryManageCommand;
using T.Personnel.API.Application.Command.ManageCommand;
using T.Personnel.API.Application.Command.ResignationManageCommand;

namespace T.Personnel.API.Controllers
{
    /// <summary>
    /// 人事管理-离职办理-写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ResignationManageController : ControllerBase
    {
        private readonly IMediator mediator;

        public ResignationManageController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加离职办理信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddResignationManageAsync(AddResignationManageCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
                throw;
            }
        }

        /// <summary>
        /// 删除离职信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelResignationManageAsync([FromQuery] DelResignationManageCommand command)
        {
            ApiResult<int> apiResult = new ApiResult<int>();
            try
            {
                apiResult.Data = await mediator.Send(command);
                return apiResult;
            }
            catch (Exception ex)
            {
                apiResult.Code = 500;
                apiResult.Message = ex.Message;
                throw;
            }
        }

        /// <summary>
        /// 修改离职信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdResignationManageAsync(UpdResignationManageCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Data = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.Message;
                throw;
            }
        }
    }
}
